package com.jdl.iscm.page;

import com.google.common.collect.Lists;
import com.jdl.iscm.common.CommonCmpt;
import com.jdl.iscm.common.JoinUtil;
import com.jdl.iscm.entity.enums.StockDimensionEnum;
import com.jdl.iscm.entity.excel.VltExcel;
import com.jdl.iscm.entity.proterties.ReplenishXpathProperties;
import com.jdl.iscm.page.interfaces.ManualAddInterface;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: Ran
 * @Date: 2021/8/19
 **/

@Component
public class VltPage implements ManualAddInterface<VltExcel> {

    @Autowired
    private CommonCmpt commonCmpt;

    /**
     * 手工添加
     *
     * @param webDriver
     * @param xpathProperties
     */
    @Override
    public void manualAdd(WebDriver webDriver, ReplenishXpathProperties xpathProperties) {
        commonCmpt.click(webDriver, xpathProperties.getConfigAdd());
    }

    /**
     * 手工添加设置
     *
     * @param webDriver
     * @param xpathProperties
     * @param vltExcel
     */
    @Override
    public void manualAddSetting(WebDriver webDriver, ReplenishXpathProperties xpathProperties, VltExcel vltExcel) {
        //1、设置运输方式
        commonCmpt.drpDwnClick(webDriver, xpathProperties.getConfigVltTransTypeInput(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getTransType())));
        //2、设置Vlt
        commonCmpt.input(webDriver, xpathProperties.getConfigVltVltInput(), vltExcel.getVlt());
        //3、设置Alt
        commonCmpt.input(webDriver, xpathProperties.getConfigVltAltInput(), vltExcel.getAlt());
        //4、根据配置的维度设置
        StockDimensionEnum dimensionEnum = StockDimensionEnum.ofCode(vltExcel.getDimension());
        switch (dimensionEnum) {
            case NoSKU:
                commonCmpt.click(webDriver, xpathProperties.getConfigVltNoSku());
                commonCmpt.drpDwnSeachClick(webDriver, xpathProperties.getConfigWhOutInput(), vltExcel.getOutWh(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getOutWh())));
                commonCmpt.drpDwnSeachClick(webDriver, xpathProperties.getConfigWhInInput(), vltExcel.getInWh(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getInWh())));
                commonCmpt.drpDwnClick(webDriver, xpathProperties.getConfigDimKindInput(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getKind())));
                break;
            case SKU:
                commonCmpt.click(webDriver, xpathProperties.getConfigVltSku());
                commonCmpt.drpDwnSeachClick(webDriver, xpathProperties.getConfigWhOutInput(), vltExcel.getOutWh(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getOutWh())));
                commonCmpt.drpDwnSeachClick(webDriver, xpathProperties.getConfigWhInInput(), vltExcel.getInWh(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getInWh())));
                commonCmpt.drpDwnSeachClick(webDriver, xpathProperties.getConfigDimSkuInput(), vltExcel.getSku(), Lists.newArrayList(JoinUtil.textJoin(xpathProperties, vltExcel.getSku())));
                break;
            case Global:
                commonCmpt.click(webDriver, xpathProperties.getConfigVltGlobal());
                break;
        }
    }

    /**
     * 手工添加提交
     *
     * @param webDriver
     * @param xpathProperties
     */
    @Override
    public void manualAddSubmit(WebDriver webDriver, ReplenishXpathProperties xpathProperties) {
        commonCmpt.click(webDriver, xpathProperties.getConfigSubmit());
    }

}
